# Maintainer: Lubosz Sarnecki <lubosz@gmail.com>

_realname=gst-python
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-gst-python")
pkgver=1.18.2
pkgrel=1
pkgdesc="GStreamer GObject Introspection overrides for Python (mingw-w64)"
arch=('any')
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-python-gobject")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
url='https://gstreamer.freedesktop.org/modules/gst-python.html'
source=(https://gstreamer.freedesktop.org/src/gst-python/${_realname}-${pkgver}.tar.xz)
sha256sums=('e19d0f760b353e88161b3712193cffbd79bf1314418da792b5fec4d8ecef389c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    --wrap-mode=nofallback \
    -Dauto_features=enabled \
    -Dpython=${MINGW_PREFIX}/bin/python.exe \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja.exe
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja.exe install

  # The python plugin loader makes problems because it links against libpython
  # which might be in conflict one already used loading the plugin.
  # The overrides don't need it so just remove it for now.
  # https://github.com/Alexpux/MINGW-packages/issues/2034
  rm -r "${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0"
}
